<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>生成任意表格</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        body {
            text-align: center;
        }

        table {
            border-collapse: collapse;
            margin: auto;
            margin-top: 50px;
        }

        tr {
            border: 1px solid black;
        }

        tr td {
            border: 1px solid black;
            width: 100px;
            height: 30px;
        }
    </style>
</head>

<body>
    <label for="row">行:</label>
    <input type="text" id="row">
    <label for="col">列:</label>
    <input type="text" id="col">
    <button>生成表格</button>
    <table>
        <!-- <tr>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>
        </tr> -->
    </table>
</body>
<script>
    (function () {
        let table = document.querySelector('table');
        let row = document.getElementById('row');
        let col = document.getElementById('col');
        let btn = document.querySelector('button');

        btn.addEventListener('click', () => {
            table.innerHTML = '';
            var frg = document.createDocumentFragment();
            for (let i = 0; i < row.value; i++) {
                var trs = document.createElement('tr');
                for (let i = 0; i < col.value; i++) {
                    var tds = document.createElement('td');
                    trs.appendChild(tds);
                }
                frg.appendChild(trs);
            }
            table.appendChild(frg);
        })







    })();
</script>

</html>